import { app, root } from "@/api/apiRoot";
import { defHttp } from '@/utils/http';
import { AppShareLogData, AppShareLogResult, IMiniProgramCodeData } from "./types";

export const Api = {
  fileUpload: root + 'dfs/upload',
  imgUpload: root + 'dfs/image_upload',
  videoUpload: root + 'dfs/video_upload',

  addAppShareLog: root + 'shareLog/add', // 添加分享内容
  getAppShareLog: root + 'shareLog/getById', // 获取分享内容
  miniProgramCode: root + 'shareLog/getQRcode',
}

/**
 * @description 获取分享内容
 * @date 18/10/2022
 * @export
 * @param {number} id
 */
export function getAppShareLog(id: string) {
  return defHttp.get<AppShareLogResult>({
    url: Api.getAppShareLog + `/${id}`,
  });
}

/**
 * @description 添加一条分享日志, 将分享参数存入云端
 * @date 18/10/2022
 * @export
 * @param {AppShareLogData} data
 */
export function addAppShareLog(data: AppShareLogData) {
  return defHttp.post<AppShareLogResult>({
    url: Api.addAppShareLog,
    data,
  });
}

/**
 * 获取小程序二维码
 * @export
 * @param {IMiniProgramCodeData} data
 * @return {*} {Promise<string>}
 */
export function miniProgramCode(data: IMiniProgramCodeData): Promise<string> {
  return defHttp.post({
    url: Api.miniProgramCode,
    data,
  });
}